package com.snicesoft.jfinal.vue.source;

import com.jfinal.template.source.FileSource;
import com.jfinal.template.source.ISource;
import com.jfinal.template.source.ISourceFactory;

public class HttpOrFileSourceFactory implements ISourceFactory {
    @Override
    public ISource getSource(String baseTemplatePath, String fileName, String encoding) {
        if (fileName.contains("http://")) {
            String url = fileName.substring(1);
            if (fileName.endsWith("/index")) {
                url = fileName.substring(1, fileName.lastIndexOf("/index"));
            }
            return new HttpSource(url);
        }
        return new FileSource(baseTemplatePath, fileName, encoding);
    }
}
